#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
#define DISABLESTEAMWORKS
#endif
using System;
using System.Collections.Generic;
using UnityEngine;
#if !DISABLESTEAMWORKS
using Steamworks;
#endif

namespace Gj.Steam
{

    public class User: SocialManager.PlatformAuth
    {
        private static User instance;
        private static SocialManager.AuthDelegate Callback;

        static User()
        {
            instance = new User();
            
        }
        public static SocialManager.PlatformAuth Auth()
        {
            return instance;
        }

#if !DISABLESTEAMWORKS
        public static void GetTicketForWebApiResponse(GetTicketForWebApiResponse_t response)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            
            var s = BitConverter.ToString(response.m_rgubTicket);
            // Debug.LogError("steam ticket:"+response.ToString()+"->"+s+":"+s.Replace("-", ""));
            dic["code"] = s.Replace("-", "");
            dic["state"] = "login";
            dic["openId"] = dic["code"];
            dic["nickName"] = "";
            dic["avatar"] = "";
            // 进入游戏
            Callback(SocialManager.Platform.Steam, SocialManager.SUCCESS, dic);
        }
#endif
        public async void IsAuthorized(SocialManager.AuthDelegate callback)
        {
            Callback = callback;
            
#if !DISABLESTEAMWORKS
            var ticket = SteamUser.GetAuthTicketForWebApi("login");
#else
            callback(SocialManager.Platform.Steam, 0, null);
#endif
        }

        public async void Authorize(SocialManager.AuthDelegate callback)
        {
            Callback = callback;

#if !DISABLESTEAMWORKS
            var ticket = SteamUser.GetAuthTicketForWebApi("login");
#else
            callback(SocialManager.Platform.Steam, 0, null);
#endif
        }

        public void Real(SocialManager.RealDelegate callback)
        {
        }

        public void SubmitLeaderboard(string key, int value, SocialManager.LeaderboardDelegate callback)
        {
        }

        public void AddAchievement(string key, int value, SocialManager.AchievementDelegate callback)
        {
        }

        public bool CanLocalShare()
        {
            return false;
        }

        public void DirectShare(string title, string imagePath, string description, string targetUrl, string videoUrl,
            SocialManager.ShareDelegate callback)
        {
        }

        public async void Logout(SocialManager.LogoutDelegate callback)
        {
            callback(SocialManager.Platform.Steam);
        }
    }
}